#include <stdio.h>
#include <string.h>
#include <assert.h>


int main(int argc, char* argv[])
{
    if(argc != 3) {
        fprintf(stderr, "topcpu FILE PROCNAME\n");
        return 0;
    }

    const char* path = argv[1];
    const char* proc_name = argv[2];

    FILE* fp = fopen(path, "r");
    assert(NULL != fp);
    
    #define LEN 100
    int pid;
    int ppid;
    char user[LEN];
    char stat[LEN];
    float vsz;
    float mem;
    int cpu_no;
    float cpu_rate;
    char command[LEN];

    char line[LEN] = {0};

    while(1) {
        char* tmp = fgets(line, LEN-1, fp);
        if(NULL == tmp) {
            break;
        }
        printf("%s", tmp);
        int n = sscanf(line, "%d%d%s%s%f%f%d%f%s", 
                &pid, &ppid, user, stat, &vsz, &mem, &cpu_no, &cpu_rate, command);
        printf("n=%d (%s).\n", n, "line");







    }

    return 0;
}
